package com.bootdo.system.service.impl;

import com.bootdo.system.dao.DlCompanyDao;
import com.bootdo.system.domain.DlCompanyDO;
import com.bootdo.system.vo.UpcomingListAlbum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.bootdo.system.dao.DlCompanyAlbumDao;
import com.bootdo.system.domain.DlCompanyAlbumDO;
import com.bootdo.system.service.DlCompanyAlbumService;



@Service
public class DlCompanyAlbumServiceImpl implements DlCompanyAlbumService {
	@Autowired
	private RedisTemplate redisTemplate;
	@Autowired
	private DlCompanyAlbumDao dlCompanyAlbumDao;
	@Autowired
	private DlCompanyDao dlCompanyDao;

	@Override
	public DlCompanyAlbumDO get(Integer companyAlbumId){
		return dlCompanyAlbumDao.get(companyAlbumId);
	}
	
	@Override
	public List<DlCompanyAlbumDO> list(Map<String, Object> map){
		return dlCompanyAlbumDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return dlCompanyAlbumDao.count(map);
	}
	
	@Override
	public int save(DlCompanyAlbumDO dlCompanyAlbum){
		return dlCompanyAlbumDao.save(dlCompanyAlbum);
	}
	
	@Override
	public int update(DlCompanyAlbumDO dlCompanyAlbum){
		if(dlCompanyAlbum.getCompanyId() != null){
			String[] ids = dlCompanyAlbum.getCompanyId().split(",");
			return dlCompanyAlbumDao.updateStatus(ids, dlCompanyAlbum.getAuditStatus());
		}else {
			return 0;
		}

	}
	
	@Override
	public int remove(Integer companyAlbumId){
		return dlCompanyAlbumDao.remove(companyAlbumId);
	}
	
	@Override
	public int batchRemove(Integer[] companyAlbumIds){
		return dlCompanyAlbumDao.batchRemove(companyAlbumIds);
	}

    @Override
    public void updateStatus(String[] ids, String type) {
		dlCompanyAlbumDao.updateStatus(ids, type);
    }

    @Override
    public void auditFailureText(String auditFailureText, String ids) {
		if(ids != null){
			String[] split = ids.split(",");
			for (String id:split) {
				redisTemplate.opsForValue().set(id + "companyAlbumAuditFailureText" , auditFailureText);
			}
		}
    }

    @Override
    public List<UpcomingListAlbum> upcomingList(Map<String, Object> map) {
		List<UpcomingListAlbum> list = dlCompanyAlbumDao.upcomingList(map);
		for (UpcomingListAlbum upcomingListAlbum : list) {
			upcomingListAlbum.setIsFlag(1);
		}
		List<UpcomingListAlbum> agent = dlCompanyDao.getAgent(map);
		for (UpcomingListAlbum upcomingListAlbum : agent) {
			upcomingListAlbum.setIsFlag(2);
		}
		list.addAll(agent);
		return list;
    }

}
